'use strict';

const { getDefaultModelConfig } = require('../../utils/common');
const {formatDecimal} = require("../../utils");

module.exports = app => {
  const { STRING, INTEGER, DECIMAL, TEXT, TIME } = app.Sequelize;

  const TicketShop = app.model.define('ticket_shop', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: '主键ID'
    },
    name: {
      type: STRING(100),
      allowNull: false,
      comment: '景点名称'
    },
    cover: {
      type: STRING(255),
      allowNull: true,
      comment: '封面图片URL'
    },
    carousel: {
      type: TEXT,
      allowNull: true,
      comment: '轮播图片URL列表，用逗号分隔'
    },

    open_start_time: {
      type: TIME,
      allowNull: true,
      comment: '开放时间'
    },
    open_end_time: {
      type: TIME,
      allowNull: true,
      comment: '结束时间'
    },
    description: {
      type: STRING(255),
      allowNull: false,
      comment: '描述'
    },
    content: {
      type: TEXT,
      allowNull: true,
      comment: '内容'
    },
    sale_count: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '销量'
    },
    // 虚拟销量
    virtual_sale_count: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '虚拟销量'
    },
    price: {
      type: DECIMAL(10, 2),
      allowNull: false,
      defaultValue: 0,
      comment: '价格',
      get() {
        return formatDecimal(this.getDataValue('price'));
      }
    },
    original_price: {
      type: DECIMAL(10, 2),
      allowNull: false,
      defaultValue: 0,
      comment: '原价',
      get() {
        return formatDecimal(this.getDataValue('original_price'));
      }
    },
    level: {
      type: STRING(255),
      allowNull: true,
      comment: '描述'
    },
    address: {
      type: STRING(255),
      allowNull: false,
      comment: '详细地址'
    },
    longitude: {
      type: STRING,
      allowNull: true,
      comment: '经度'
    },
    latitude: {
      type: STRING,
      allowNull: true,
      comment: '纬度'
    },
    is_recommended: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '是否推荐(0-否,1-是)'
    },
    status: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '状态(0-下架,1-上架)'
    },
    username: {
      type: STRING(255),
      allowNull: true,
      comment: '用户名'
    },
    password: {
      type: STRING(255),
      allowNull: true,
    },
    ...getDefaultModelConfig(app)
  }, {
    tableName: 'ticket_shop',
    timestamps: true,
    createdAt: 'create_time',
    updatedAt: 'update_time',
    comment: '景点信息表'
  });

  return TicketShop;
};
